<template>
  <dynamic-form :data="data" @data-changed="dataChanged"></dynamic-form>
  <el-button @click="onSaveSimulationConfig">{{ $tr("Save") }}</el-button>
</template>

<script lang="ts">
import { getSimulationConfig, saveSimulationConfig } from "@/api/cards";
import DynamicForm from "@/components/dynamicform/DynamicForm.vue";
import { ElMessage } from "element-plus";
import { ref, defineComponent } from "vue";
import { FieldType } from "../dynamicform/formdatastruct";
import { SimulationConfig } from "../flowchart/models";
export default defineComponent({
  components: { DynamicForm },
  setup() {
    const dialogVisible = ref(false);
    const data = ref<Record<string, FieldType>>({});
    const formValue = {} as SimulationConfig
    return { dialogVisible, data, formValue };
  },
  methods: {
    dataChanged(evt: SimulationConfig) {
      this.formValue = evt
      // if (evt.stop_time == null) {
      //   ElMessage.error("Stop time of simulation is unset");
      //   return;
      // }
    },
    handleClose() {
      this.dialogVisible = false;
    },
    onSaveSimulationConfig(){
      saveSimulationConfig(this.formValue)
    }
  },
  mounted() {
    getSimulationConfig().then((config) => {
      this.data = config;
    });
    
  },
});
</script>
